package com.bocai;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;


/**
 * 封装的接口响应。
 * <p>
 * 默认为JSON格式返回。如果需要返回原始数据，则需要把<b>raw</b>设为<code>true</code>，result则作为字符串直接返回。
 * </p>
 *
 */
public class Response {
	private int code = ResponseCode.SUCCESS.getValue();
	private String msg;
	@JsonInclude(JsonInclude.Include.NON_NULL)
	private Object result;
	@JsonIgnore
	private String contentType = "application/json;;charset=UTF-8";
	
	public Response() {
	}
	
	public Response(Object result) {
		this.code = ResponseCode.SUCCESS.getValue();
		this.msg = ResponseCode.SUCCESS.getDesc();
		this.result = result;
	}
	
	public Response(int code, String msg) {
		this.code = code;
		this.msg = msg;
	}
	
	public Response(int code, String msg, Object result) {
	    this(result);
		this.code = code;
		this.msg = msg;
	}
	
	public int getCode() {
		return code;
	}
	
	public void setCode(int code) {
		this.code = code;
	}
	
	public String getMsg() {
		return msg;
	}
	
	public void setMsg(String msg) {
		this.msg = msg;
	}
	
	public Object getResult() {
		return result;
	}

	public void setResult(Object result) {
		this.result = result;
	}

	public String toString() {
	    return "Response: {code: " + code + ", msg: " + msg + ", result: " + result + "}";
	}
}
